package com.ruoyi.Evaluation.mapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.ruoyi.Evaluation.domain.Evaluation;
import com.ruoyi.Evaluation.vo.EvaluationStat;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

/**
 * 评分信息Mapper接口
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
public interface EvaluationMapper 
{
    /**
     * 查询评分信息
     * 
     * @param resultId 评分信息主键
     * @return 评分信息
     */
    public Evaluation selectEvaluationByResultId(Long resultId);

    /**
     * 查询评分信息列表
     * 
     * @param evaluation 评分信息
     * @return 评分信息集合
     */
    public List<Evaluation> selectEvaluationList(Evaluation evaluation);

    /**
     * 新增评分信息
     * 
     * @param evaluation 评分信息
     * @return 结果
     */
    public int insertEvaluation(Evaluation evaluation);

    /**
     * 修改评分信息
     * 
     * @param evaluation 评分信息
     * @return 结果
     */
    public int updateEvaluation(Evaluation evaluation);

    /**
     * 删除评分信息
     * 
     * @param resultId 评分信息主键
     * @return 结果
     */
    public int deleteEvaluationByResultId(Long resultId);

    /**
     * 批量删除评分信息
     * 
     * @param resultIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteEvaluationByResultIds(Long[] resultIds);

    //根据学位点ID 查询评分信息
    @Select("select * from evaluation where point_id = #{userId}")
    public Evaluation selectByPointId(Long userId);

    //查询个评分的数量
    @Select("SELECT \n" +
            "  evaluation, \n" +
            "  COUNT(*) AS total_count\n" +
            "FROM (\n" +
            "  SELECT point_id, student_evaluation AS evaluation FROM ceshi.evaluation\n" +
            "  UNION ALL\n" +
            "  SELECT point_id, tutors_evaluation AS evaluation FROM ceshi.evaluation\n" +
            "  UNION ALL\n" +
            "  SELECT point_id, courses_evalutaion AS evaluation FROM ceshi.evaluation  -- 修正字段名拼写\n" +
            "  UNION ALL\n" +
            "  SELECT point_id, research_evaluation AS evaluation FROM ceshi.evaluation\n" +
            "  UNION ALL\n" +
            "  SELECT point_id, papers_evaluation AS evaluation FROM ceshi.evaluation\n" +
            "  UNION ALL\n" +
            "  SELECT point_id, awards_evaluation AS evaluation FROM ceshi.evaluation\n" +
            ") AS combined_data\n" +
            "WHERE point_id = #{userId}\n" +
            "GROUP BY evaluation\n" +
            "ORDER BY \n" +
            "  CASE \n" +
            "    WHEN evaluation = '优秀' THEN 1\n" +
            "    WHEN evaluation = '良好' THEN 2\n" +
            "    WHEN evaluation = '及格' THEN 3\n" +
            "    WHEN evaluation = '不及格' THEN 4\n" +
            "    ELSE 5  -- 其他情况，可以放在最后\n" +
            "  END;\n")
    ArrayList<EvaluationStat> selectCountEvaluation(Long userId);
}
